<?php
namespace Infinity;


class Url {
  private $query_params;

  public function __construct($path='') {
    if(empty($path))
      $this->query_params = $_GET;
    else
      $this->query_params = array('q' => $path);
  }

  public function getQuery($key, $default='') {
    if(isset($query_params[$key]))
      return $query_params[$key];
    return $default;
  }

  public function setQuery($key, $value) {
    $this->query_params[$key] = $value;
    return $this;
  }

  public function delQuery($key) {
    unset($this->query_params[$key]);
    return $this;
  }

  public function getUrl() {
    $query = $this->query_params;
    unset($query['q']);
    return url($this->query_params['q'], array(
      'absolute' => true,
      'query' => $query
    ));
  }
} 